# 设置请求头

import requests

'''
为什么要设置请求头
模拟浏览器，欺骗服务器，获取和浏览器一致的内容
'''

url = 'https://www.baidu.com'

header = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'
}

r = requests.get(url, headers=header)
# r = requests.request('GET', url=url, headers=header)
r.encoding = 'utf-8'
print(r.text)
# print(r.content.decode('utf-8'))
